package com.nidu.demo.post.model;

import com.alibaba.cola.exception.BizException;
import com.nidu.demo.base.BaseDeletableEntity;
import com.nidu.demo.base.BaseTenantEntity;
import com.nidu.demo.common.enums.BooleanEnum;
import com.nidu.demo.common.exception.ErrorCodeConstants;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * 职位领域对象
 *
 * @author auto
 */
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
public class Position extends BaseTenantEntity implements BaseDeletableEntity {

    private Long id;

    /**
     * 职位名称
     */
    private String postName;

    /**
     * 职位编码
     */
    private String postCode;

    /**
     * 公司ID
     */
    private Long companyId;

    /**
     * 描述
     */
    private String remark;

    /**
     * 排序值
     */
    private Integer sortOrder;
    /**
     * 是否删除
     */
    private Boolean deleted;

    /**
     * 创建职位
     * @param name
     * @param code
     * @param companyId
     * @param description
     * @param sortOrder
     * @return
     */
    public static Position create(String name, String code, Long companyId, String remark, Integer sortOrder) {
        Position post = new Position();
        post.setPostName(name)
                .setPostCode(code)
                .setCompanyId(companyId)
                .setRemark(remark)
                .setSortOrder(sortOrder);
        return post;
    }

    /**
     * 更新职位
     * @param id
     * @param name
     * @param code
     * @param companyId
     * @param description
     * @param sortOrder
     * @return
     */
    public static Position update(Long id, String name, String code, Long companyId, String remark, Integer sortOrder) {
        Position post = new Position();
        post.setId(id)
                .setPostName(name)
                .setPostCode(code)
                .setCompanyId(companyId)
                .setRemark(remark)
                .setSortOrder(sortOrder);
        return post;
    }

    @Override
    public void isDeleted() {
        if (BooleanEnum.TRUE.getValue().equals(this.getDeleted())) {
            throw new BizException(ErrorCodeConstants.POSITION_NOT_FOUND.getCode(), ErrorCodeConstants.POSITION_NOT_FOUND.getMessage());
        }
    }

}